//
//  CTDataManager.m
//  CT
//
//  Created by liufanwei on 15/4/20.
//  Copyright (c) 2015年 liufanwei. All rights reserved.
//

#import "CTDataManager.h"

@implementation CTDataManager
@synthesize HistoryManager;
@synthesize ContactManager;


+(CTDataManager*)shareInstance{
    static dispatch_once_t onceToken;
    static CTDataManager * dataManager;
    dispatch_once(&onceToken, ^{
        dataManager = [[CTDataManager alloc] init];
        dataManager.ContactManager = [CTContactManager share];
        dataManager.HistoryManager = [CTHistoryManager shareInstance];
        __weak CTDataManager *wkSelf = dataManager;
        dataManager.ContactManager.callback = ^(CTContactManager * contactmanager){
            [wkSelf.HistoryManager reload];
            [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiCationLoadContactsReply object:Nil];
        };
    });
    return dataManager;
}


- (instancetype)init
{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onNotifyCation:) name:kNotifiCationLoadContactsRequest object:Nil];
    }
    return self;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


-(void)onNotifyCation:(NSNotification*)sender{
    if ([sender.name isEqualToString:kNotifiCationLoadContactsRequest]) {
        [ContactManager reload];
    }
}
@end
